package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * 卢米埃订阅用户
 *
 * @author yliyun
 * @date 2022/10/24
 */
@Data
@TableName("lumiere_subscribe_user")
public class LumiereSubscribeUser {
    /**
     * 被删除
     */
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    /**
     * 不删除
     */
    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    private Integer id;

    /**
     * 订阅id
     */
    private Integer subscribeId;

    /**
     * 用户id
     */
    private Integer userId;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 商店id
     */
    private Integer shopId;

    /**
     * 商品id
     */
    private Integer goodsId;

    /**
     * 货物产品id
     */
    private Integer goodsProductId;

    /**
     * 数量
     */
    private Integer number;

    /**
     * 商品项目
     */
    private String goodsItem;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 税价格
     */
    private BigDecimal taxPrice;

    /**
     * 地址标识
     */
    private Integer addressId;

    /**
     * 方法
     */
    private Byte method;

    /**
     * 交货方法
     */
    private Byte deliveryMethod;

    /**
     * 交货日
     */
    private Integer[] deliveryDays;

    /**
     * 交付开始时间
     */
    private LocalTime deliveryStartTime;

    /**
     * 交付结束时间
     */
    private LocalTime deliveryEndTime;

    /**
     * 开始时间
     */
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    private LocalDateTime endTime;

    /**
     * 汽车子
     */
    private Boolean autoSub;

    /**
     * 汽车支付类型
     */
    private Byte autoPayType;

    /**
     * 汽车支付id
     */
    private Integer autoPayId;

    /**
     * 链接id
     */
    private Integer linkId;

    /**
     * 备注
     */
    private String remark;

    /**
     * 状态
     */
    private Integer status;

    /**
     * 到期时间
     */
    private LocalDateTime expireTime;

    /**
     * 添加时间
     */
    private LocalDateTime addTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 删除
     */
    private Boolean deleted;

    /**
     * 交付日期
     */
    private String[] deliveryDates;

    /**
     * 购买者身份证
     */
    private Integer purchaserId;

    /**
     * 规则id
     */
    private Integer ruleId;

    /**
     * 点
     */
    private Integer point;

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        subscribeId("subscribe_id", "subscribeId", "INTEGER", false),
        userId("user_id", "userId", "INTEGER", false),
        userName("user_name", "userName", "VARCHAR", false),
        shopId("shop_id", "shopId", "INTEGER", false),
        goodsId("goods_id", "goodsId", "INTEGER", false),
        goodsProductId("goods_product_id", "goodsProductId", "INTEGER", false),
        number("number", "number", "INTEGER", true),
        goodsItem("goods_item", "goodsItem", "VARCHAR", false),
        price("price", "price", "DECIMAL", false),
        taxPrice("tax_price", "taxPrice", "DECIMAL", false),
        addressId("address_id", "addressId", "INTEGER", false),
        method("method", "method", "TINYINT", true),
        deliveryMethod("delivery_method", "deliveryMethod", "TINYINT", false),
        deliveryDays("delivery_days", "deliveryDays", "VARCHAR", false),
        deliveryStartTime("delivery_start_time", "deliveryStartTime", "TIME", false),
        deliveryEndTime("delivery_end_time", "deliveryEndTime", "TIME", false),
        startTime("start_time", "startTime", "TIMESTAMP", false),
        endTime("end_time", "endTime", "TIMESTAMP", false),
        autoSub("auto_sub", "autoSub", "BIT", false),
        autoPayType("auto_pay_type", "autoPayType", "TINYINT", false),
        autoPayId("auto_pay_id", "autoPayId", "INTEGER", false),
        linkId("link_id", "linkId", "INTEGER", false),
        remark("remark", "remark", "VARCHAR", false),
        status("status", "status", "INTEGER", true),
        expireTime("expire_time", "expireTime", "TIMESTAMP", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false),
        deliveryDates("delivery_dates", "deliveryDates", "VARCHAR", false),
        purchaserId("purchaser_id", "purchaserId", "INTEGER", false),
        ruleId("rule_id", "ruleId", "INTEGER", false),
        point("point", "point", "INTEGER", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}